//
//$Id: grids_common.h 722 2012-11-29 17:33:43Z andrew.tsyganov $

#pragma once

#include "subset.h"
#include "types.h"

const size_t kDefaultGridsCapacity = 2048;

class Grid
{
private:
    Subset rows_, columns_;
public:
    inline size_t size() { return rows_.count()*columns_.count(); }
    inline void clear() { rows_.remove(); columns_.remove(); }
    inline void optimize() { rows_.optimize(); columns_.optimize(); }

    inline Subset const& get_Rows() const { return rows_; }
    inline Subset const& get_Columns() const { return columns_; }

    inline void init(Subset const& r, Subset const& c) { rows_ = r; columns_ = c; }
    inline void set_Rows(Subset const& r) { rows_ = r; }
    inline void set_Columns(Subset const& c) { columns_= c; }

    std::string to_String(Brackets_Type const bt = BRACES, int const add = 0) const;
    friend bool operator <=(Grid const& lhs, Grid const& rhs) { return ((lhs.rows_ <= rhs.rows_) && (lhs.columns_ <= rhs.columns_)); }
    friend bool operator ==(Grid const& lhs, Grid const& rhs) { return ((lhs.rows_ == rhs.rows_) && (lhs.columns_ == rhs.columns_)); }

    unsigned char* serialize(Subset_Serializer& ss, unsigned& len);
    void deserialize(unsigned char* buf);
};

void PrintGridsTXT(std::ostream& os, std::vector<Grid> const& vg);
void PrintGridsLaTeX(std::ostream& os, std::vector<Grid> const& vg);
void PrintGridsSetTXT(std::ostream& os, std::vector<Grid> const& vg, Subset const& s);
void PrintGridsSetLaTeX(std::ostream& os, std::vector<Grid> const& vg, Subset const& s);

bool MakeGridByRows(Bool_Matrix const& matr, Subset const& rs, Grid& g);
bool MakeGridByColumns(Bool_Matrix const& matr, Subset const& cs, Grid& g);

void FindGridsSEQ(Bool_Matrix const& matr, std::vector<Grid>& grids);

//EOF!
